package gold.digger;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC441 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int arrangeCoins(int n) {
            int left = 1, right = Integer.MAX_VALUE;
            while (left <= right) {
                int mid = left + (right - left) / 2;
                long rowSum = 1L * mid * (mid + 1) / 2;
                if (n == rowSum) return mid;
                if (n > rowSum) left = mid + 1;
                if ((n < rowSum)) right = mid - 1;
            }

            return left - 1;
        }
    }

    public void run() {
        Solution solution = new Solution();
        System.out.println(solution.arrangeCoins(1957747793));
    }

    public static void main(String[] args) throws Exception {
        LC441 an = new LC441();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
